//
//  KFDSettingsViewController.m
//  KFD
//
//  Created by JIRENTIANXIANG on 7/4/15.
//  Copyright © 2015 kfd. All rights reserved.
//

#import "KFDSettingsViewController.h"
#import "KFDUIConfigurator.h"
#import "KFDAccountManager.h"
#import "JTToast.h"

@interface KFDSettingsViewController ()

@end

@implementation KFDSettingsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    KFDUIConfigurator* uiConfigurator=[KFDUIConfigurator configuratorForViewController:self];
    [uiConfigurator configureNavigationBarWithBackAction:@selector(goBack)];
    self.title=@"系统设置";
}

-(void)goBack
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

//---------------------------------------------------------------------
#pragma mark - Table view delegate
//---------------------------------------------------------------------
-(void)tableView:(nonnull UITableView *)tableView didSelectRowAtIndexPath:(nonnull NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.row==4) {
        UIAlertController* alertController=[UIAlertController alertControllerWithTitle:nil message:@"确定退出登录？" preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction* cancel=[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:nil];
        UIAlertAction* confirm=[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * __nonnull action) {
            KFDAccountManager* manager=[KFDAccountManager sharedManager];
            [manager logout];
            if (![manager isLogin]) {
                [[JTToast makeText:@"已退出登录"] showInView:self.view size:CGSizeMake(100,40)];
            }
        }];
        [alertController addAction:cancel];
        [alertController addAction:confirm];
        [self presentViewController:alertController animated:YES completion:nil];
    }
}
//---------------------------------------------------------------------

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
